# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do

  def updateProjectBuildNumber
 
      currentTime = Time.new.strftime("%Y%m%d")
      build = get_build_number()
      if build.include?"#{currentTime}."
        # => 为当天版本 计算迭代版本号
      lastStr = build[build.length-2..build.length-1]
      lastNum = lastStr.to_i
      lastNum = lastNum + 1
      lastStr = lastNum.to_s
        if lastNum < 10
          lastStr = lastStr.insert(0,"0")
        end
      build = "#{currentTime}.#{lastStr}"
      else
      # => 非当天版本 build 号重置
      build = "#{currentTime}.01"
      end
      puts("*************| 更新build #{build} |*************")
      # => 更改项目 build 号
      increment_build_number(
      build_number: "#{build}"
      )
  end


  desc "Push a new beta build to TestFlight"
  lane :beta do

    increment_build_number
    
    build_app(
	     #  workspace: "BOQRPay.xcodeproj",
	       scheme: "BOQRPay",
	       configuration: "Debug",
	       silent: true,
  	       clean: true,
	     #  output_directory: "path/to/dir",
	       output_name: "BOQRPay-Staging.ipa",
              

)
    
    upload_to_testflight(skip_waiting_for_build_processing: true)
   release
  end
    lane :release do
    increment_build_number
    build_app(
        # workspace: "BOQRPay.xcodeproj",
         scheme: "BOQRPay",
         configuration: "Release",
         silent: true,
         clean: true,
        # output_directory: "path/to/dir",
         output_name: "BOQRPay-Release.ipa",


)
    
    upload_to_testflight(skip_waiting_for_build_processing: true)
    test
  end
    lane :test do
    increment_build_number
    build_app(
       #  workspace: "BOQRPay.xcodeproj",
         scheme: "BOQRPay",
         configuration: "Test",
         silent: true,
         clean: true,
        # output_directory: "path/to/dir",
         output_name: "BOQRPay-test.ipa",


)
    
    upload_to_testflight(skip_waiting_for_build_processing: true)
  end
end
